import api from './api'

// 订单相关API
const orderAPI = {
  // 提交订单
  submitOrder(data) {
    return api.post('/order/submit', data)
  },
  
  // 获取订单列表
  getOrderList(params = {}) {
    return api.get('/order/list', {
      params: {
        page: params.page || 1,
        pageSize: params.pageSize || 10,
        status: params.status, // all, pending, processing, shipped, completed, cancelled, refunding, refunded
        startTime: params.startTime,
        endTime: params.endTime,
        ...params
      }
    })
  },
  
  // 获取订单详情
  getOrderDetail(orderId) {
    return api.get(`/order/detail/${orderId}`)
  },
  
  // 取消订单
  cancelOrder(orderId) {
    return api.post(`/order/${orderId}/cancel`)
  },
  
  // 确认收货
  confirmOrder(orderId) {
    return api.post(`/order/${orderId}/confirm`)
  },
  
  // 申请退款
  applyRefund(orderId, data) {
    return api.post(`/order/${orderId}/refund/apply`, data)
  },
  
  // 查询退款状态
  getRefundStatus(refundId) {
    return api.get(`/order/refund/${refundId}/status`)
  },
  
  // 取消退款申请
  cancelRefund(refundId) {
    return api.post(`/order/refund/${refundId}/cancel`)
  },
  
  // 创建支付订单
  createPayment(orderId, paymentMethod, data = {}) {
    return api.post(`/order/${orderId}/payment/create`, {
      paymentMethod, // alipay, wechat, bank
      ...data
    })
  },
  
  // 查询支付状态
  queryPaymentStatus(orderId) {
    return api.get(`/order/${orderId}/payment/status`)
  },
  
  // 获取订单统计数据
  getOrderStatistics() {
    return api.get('/order/statistics')
  },
  
  // 评价订单商品
  reviewOrder(orderId, data) {
    return api.post(`/order/${orderId}/review`, data)
  },
  
  // 再次购买订单商品
  buyAgain(orderId) {
    return api.post(`/order/${orderId}/buyAgain`)
  },
  
  // 获取物流信息
  getLogisticsInfo(orderId) {
    return api.get(`/order/${orderId}/logistics`)
  }
}

export default orderAPI